<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateNotesUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('notes_users', function (Blueprint $table) {
            $table->bigIncrements('id')->unsigned();
            $table->tinyInteger('is_read')->default(0)->nullable()->unsigned()->comment('是否已读');
            $table->dateTime('read_time')->nullable()->comment('阅读时间');
            $table->bigInteger('user_id')->unsigned()->comment('用户id');
            $table->foreign('user_id')->references('id')->on('users');
            $table->bigInteger('notes_id')->unsigned()->comment('消息id');
            $table->foreign('notes_id')->references('id')->on('notes');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('notes_users', function ($table) {
            $table->dropForeign(['user_id']);
            $table->dropForeign(['notes_id']);
        });
        Schema::dropIfExists('notes_users');
    }
}
